/*
 * tools functions
 *
 */

#ifndef TOOLS_H_
#define TOOLS_H_


#ifdef __cplusplus
extern "C"{
#endif

//
// get arduino voltage reference (3.3V or 5V)
// 
long    read_vcc_ref        ();

// Return RC high-pass filter output sample, 
// x input sample, x¹ last sample (n-1) 
// y¹ last output sample (n-1), 
// dt time interval, 
// RC time constant, f[Hz]=1/(2*pi*RC)
float highpass(float x, float x1 , float y1, float dt, float RC);

// Return RC low-pass filter output sample, 
// x input sample, 
// y¹ last output sample (n-1), 
// dt time interval, 
// RC time constant, f[Hz]=1/(2*pi*RC)   
//                    our use case is an lp filter at 4.08[s]=>0.24[Hz] => RC=T/(2pi) => ratio=dt*(RC+dt) => Y=X*ratio+Y1*(1-ratio)
float lowpass(float x, float y1, float dt, float RC);

//
//average filter 40ms for 1 analogue value
double fanalogRead(int pin, int wait);

//
//R = SQRT( Rx^2 + Ry^2 + Rz^2)
#define module(X,Y,Z)   (sqrt(square(X)+square(Y)+square(Z)))

//
//
#define alpha(C,R)      acos(C/R)
#define aalpha(A,R)     (cos(A)*R)



#ifdef __cplusplus
}
#endif
#endif

